<template>
	<view>
		<view class="tabbar-container" :class="isIpx?'IpxBot':''">
			<view class="tabbar-item" v-for="(item,index) in tabList" :class="[item.centerItem ? 'center-item' : '']"
				@click="changeItem(item)" :key="index">
				<view class="item-top" :style="{padding:'4px'}">
					<image :src="tabId==item.id?item.selectIcon:item.icon" mode=""></image>
				</view>
				<view class="item-bottom" :class="[tabId==item.id ? 'item-active' : '']">
					<text>{{item.text}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			currentPage: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				//适配IPhoneX
				isIpx: false,
				//底部Tab
				tabId: 0,
				tabList: [{
					id: 0,
					path: "/pages/index/index",
					icon: "../../static/tabBar/index.png",
					selectIcon: "../../static/tabBar/index_cur.png",
					text: "首页",
					centerItem: false
				}, {
					id: 1,
					path: "/pages/diction/list",
					icon: "../../static/tabBar/shop.png",
					selectIcon: "../../static/tabBar/shop_cur.png",
					text: "话术",
					centerItem: false
				}, {
					id: 2,
					path: "/pages/project/list",
					icon: "../../static/tabBar/order.png",
					selectIcon: "../../static/tabBar/order_cur.png",
					text: "教学",
					centerItem: false
				}],
			};
		},
		mounted() {
			this.tabId = this.currentPage;
			//隐藏原生tab
			uni.hideTabBar();
		},
		created() {
			// 判断为 iPhone X 给予底部距离
			let that = this
			uni.getSystemInfo({
				success: function(res) {
					if (res.model.indexOf('iPhone X') !== -1) {
						that.isIpx = true;
					}
				}
			})
		},
		methods: {
			// tab 切换
			changeItem(item) {
				console.log(item)
				uni.switchTab({
					url: item.path
				})
				// uni.navigateTo({
				// 	url: item.path
				// });
			},

		}
	}
</script>
<style scoped>
	view {
		padding: 0;
		margin: 0;
		box-sizing: border-box;
	}

	.tabbar-container {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		/* height: 100rpx; */
		box-shadow: 0px 0px 14px 0px rgb(0 0 0 / 7%);
		display: flex;
		align-items: center;
		padding: 5rpx 0;
		color: #999999;
		background-color: #FFFFFF;
	}

	.tabbar-container .tabbar-item {
		width: 100%;
		text-align: center;
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: flex-end;
		align-items: center;
		height: 100%;
		position: relative;
	}

	.tabbar-container .item-active {
		color: #0081ff;
	}

	.tabbar-container .center-item {
		display: block;
		position: relative;
	}

	.tabbar-container .tabbar-item .item-top {
		width: 70rpx;
		height: 70rpx;
		padding: 5rpx;
	}

	.tabbar-container .center-item .item-top {
		flex-shrink: 0;
		/* box-shadow: 0 0 5px #999; */
		background-color: #FFFFFF;
		width: 36px;
		height: 36px;
		position: absolute;
		z-index: 2;
		border-radius: 50%;
		top: -19px;
		left: 0px;
		right: 0;
		margin: auto;
	}

	.tabbar-container .tabbar-item .item-top image {
		width: 100%;
		height: 100%;
	}

	.tabbar-container .tabbar-item .item-bottom {
		font-size: 25rpx;
		width: 100%;
	}

	.tabbar-container .center-item .item-bottom {
		position: absolute;
		bottom: 2rpx;
	}

	/* 适配iPhone X */
	.IpxBot {
		padding-bottom: 30rpx !important;
	}
</style>
